package com.example.user.controller;

import com.example.user.po.SysUser;
import com.example.user.service.SysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author chentao
 * @version 1.0
 * @description: TODO
 * @date 2025/3/10 下午8:53
 */
@RestController
public class SysUserController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private SysUserService sysUserService;

    /****
     * 用户注册，测试2段式事务
     * @return
     */
    @RequestMapping(value = "register1")
    public boolean register1() throws Exception {
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        SysUser sysUser = new SysUser();
        sysUser.setUsername(uuid);
        sysUser.setPassword(uuid);
        return sysUserService.registerUser1(sysUser);
    }


    /****
     * 用户注册，测试2段式事务
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "register2")
    public void register2() throws Exception {
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        SysUser sysUser = new SysUser();
        sysUser.setUsername(uuid);
        sysUser.setPassword(uuid);
        this.sysUserService.registerUser2(sysUser);
        logger.warn("user save: " + sysUser);
    }
}
